<template>
  <div class="ly-box">
    <yd-slider :show-pagination="false" :callback="sliderBack" :index="navIndex">
      <yd-slider-item>
        <div class="tab-item service">
          <div class="item-img" :style="{backgroundImage: 'url(' + service.img + ')'}"></div>
          <div class="item-boxs">
            <div class="boxs-item" v-for="(item,index) in service.boxs" :key="index">
              <div @click="getAuthCode(item.url)">
                <yd-icon :name="item.icon" size=".6rem" :color="item.color"></yd-icon>
                <p>{{item.name}}</p>
              </div>
            </div>
          </div>
        </div>
      </yd-slider-item>
      <yd-slider-item>
        <div class="tab-item life">
          <div class="item-img" :style="{backgroundImage: 'url(' + life.img + ')'}"></div>
          <div class="item-boxs">
            <div class="boxs-item" v-for="(item,index) in life.boxs" :key="index">
              <a :href="item.url">
                <yd-icon :name="item.icon" size=".6rem" :color="item.color"></yd-icon>
                <p>{{item.name}}</p>
              </a>
            </div>
          </div>
        </div>
      </yd-slider-item>
    </yd-slider>
    <div class="bottom-nav">
      <div :class="sliderOne" @touchstart="aaaaa">
        <yd-icon name="home"></yd-icon>
        <p>金服务</p>
      </div>
      <div :class="sliderTwo" @touchstart="bbbbb">
        <yd-icon name="ucenter"></yd-icon>
        <p>金生活</p>
      </div>
    </div>
  </div>
</template>

<script>
  import http from "@/http";

  export default {
    data() {
      return {
        service: {},
        life: {},
        sliderOne: "nav-item active",
        sliderTwo: "nav-item",
        navIndex: 0
      };
    },
    created: function () {
      this.init();
    },
    methods: {
      // 请求数据
      init: function () {
        let params = {};
        params.housingId = this.$route.query.housingId;
        params.urlParams = location.search.substring(1);
        http
          .post("/common/getIcon", params)
          .then(res => {
            this.service = res.data.tab1;
            this.life = res.data.tab2;
          });
      },
      // 翻页返回页码 从0开始
      sliderBack: function (number) {
        console.log(number);
        if (number) {
          this.navIndex = 0;
          this.sliderTwo = "nav-item active";
          this.sliderOne = "nav-item ";
        } else {
          this.navIndex = 1;
          this.sliderOne = "nav-item active";
          this.sliderTwo = "nav-item ";
        }
      },
      aaaaa: function () {
        this.navIndex = 0;
        this.sliderOne = "nav-item active";
        this.sliderTwo = "nav-item ";
      },
      bbbbb: function () {
        this.navIndex = 1;
        this.sliderTwo = "nav-item active";
        this.sliderOne = "nav-item ";
      },
      getAuthCode: function (url) {
        if ('' != url && null != url) {
          window.location.href = url;
        } else {
          this.$dialog.toast({
            mes: '请联系管理员开通功能',
            timeout: 1500,
            icon: 'error',
          });
        }
      }
    }
  }
  ;
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
  body {
    background: #fff;
  }
</style>

<style scoped lang="scss">
  .ly-box {
    width: 100%;
    min-height: 10.06rem;
    // height: 12.06rem;
    // background: #fff;
  }

  .yd-slider {
    height: 100%;
  }

  .tab-item {
    width: 100%;
    height: 100%;
    overflow-y: scroll;
    .item-img {
      width: 100%;
      height: 3.5rem;
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center;
    }
    .item-boxs {
      width: 100%;
      height: auto;
      .boxs-item {
        width: 33.33%;
        height: 2rem;
        display: inline-block;
        text-align: center;
        border: 1px solid #ccc;
        outline: none;
        box-sizing: border-box;
        i {
          display: block;
          margin-top: 0.3rem;
        }
        p {
          line-height: 0.64rem;
          font-size: 0.36rem;
        }
      }
    }
  }

  .bottom-nav {
    width: 100%;
    height: 1.2rem;
    background: #fff;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-top: 1px solid #ccc;
    .nav-item {
      width: 50%;
      float: left;
      text-align: center;
      color: #999;
      padding-top: 0.1rem;
    }
    .active {
      color: red;
    }
  }
</style>
